<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/easyui/plugins/datagrid-detailview.js"></script>
<script type="text/javascript">
 $(function(){ 

	 $('#houseAll').datagrid({
		 pageSize:200,
		 pageList:[200],
		 toolbar:"#addHouse",
		 onSelect:function(index,rowdata){
			    var ownerName = "业主姓名: " + rowdata.ownerName + " ";
			    var ownerType ="业主类型: " + rowdata.ownerType + " ";
			    var ownerPhone="业主电话: " + rowdata.ownerPhone + " ";
			    var ownerMark ="业主描述: " + rowdata.ownerMark + " ";
				$("#onwerPanel").html(ownerName + " " + ownerType + "<br/>" + ownerPhone+"<br/>"+ ownerMark );
				getLogs(rowdata.id);
				getProgress('h'+rowdata.id);
		 }
	 	});
	 
	 $("#logTable").datagrid({
		 pageSize:200,
		 pageList:[200]
	 });
	
	//获取所有门店
	 $.ajax({  
		   type: "POST",  
		   url: "shop/getAllShopJson.html",  
		   dataType:"json",  
		   success: function(json){  
		     $("#selshopId").combobox({  
		        data:json.rows,  
		        valueField:'shopId',  
		        textField:'shopName',
		        onSelect:function(rec){
		        	search();
		        }
		     });
		     search();
		   }
		}); 
	 //获取所有用户
	 $.ajax({  
		   type: "POST",  
		   url: "employee/getAllEmployeeJson.html",  
		   dataType:"json",  
		   success: function(json){  
		     $("#employeeId").combobox({  
		        data:json.rows,  
		        valueField:'e_sn',  
		        textField:'e_name',
		        onSelect:function(rec){
		        	search();
		        }
		     });
		   }
		}); 
	 
	 $('#ProgressTable').datagrid({
		 pageSize:200,
		 pageList:[200],
		 toolbar:"#addProgress",
	 });
	 


 });
	function getLogs(id) {
		 $("#logTable").datagrid({
			 url:'logs/viewLogsJson.html?fkid='+id+"&module=house",
			 method:'get'
		 });
	 }
	
	function getProgress(id) {
		 $("#ProgressTable").datagrid({
			 url:'cusProgress/viewCusProgressJson.html?fkid='+id,
			 method:'get'
		 });
	 }

</script>
<div class="easyui-panel"  style="width:auto;height:450px;">
			<table id="houseAll" class="easyui-datagrid" style="width:auto;height:270px;"
					singleSelect="true"
					pagination="true"
					pagePosition="both"
					fitColumns="true"
					rownumbers="true"
					>
			    <thead>
				    <tr>
				    <th data-options="field:'unitName',width:200">小区</th>
				   	<th data-options="field:'address',width:100">门牌</th>
				   	<th data-options="field:'allprice',width:100">总价</th>			    
				    <th data-options="field:'unitprice',width:100">单价</th>
				 	<th data-options="field:'saleArea',width:100">面积</th>
				    <th data-options="field:'roomVO',width:100">户型</th>
				    <th data-options="field:'createTime',width:170">跟进时间</th>
				 	<th data-options="field:'floorVO',width:100">楼层</th> 
				 	<th data-options="field:'shop',width:100">门店</th>  			 	
				   	<th data-options="field:'e_name',width:100">经纪人</th>
				   	<th data-options="field:'decoration',width:100">装修</th>
				   	<th data-options="field:'type',width:100">房源类型</th>
					<th data-options="field:'houseMark',width:100">备注</th> 
				   	<th data-options="field:'ownerType',width:100">业主类型</th>
				    </tr>
			    </thead>
			   </table>
			 <div class="easyui-layout" data-options="fit:true">
				<div data-options="region:'west',split:true" style="width:220px;padding:10px">
					<div id="onwerPanel">
					   
					</div>
				</div>
				<div data-options="region:'center'" style="padding:10px">
					<div class="easyui-tabs" style="width:auto;height:200px">
						<div title="客户跟进" style="padding:10px">
							<table id="ProgressTable" class="easyui-datagrid" style="width:auto;height:270px;"
								singleSelect="true"
								pagination="true"
								pagePosition="both"
								fitColumns="true"
								rownumbers="true"
								>
						    <thead>
							    <tr>
								    <th data-options="field:'e_name',width:20">跟进人员</th>
								    <th data-options="field:'type',width:20">类型</th>	
								   	<th data-options="field:'createTime',width:70">跟进日期</th>
								   	<th data-options="field:'content',width:100">描述</th>			    
							    </tr>
						    </thead>	
						   </table>
						</div>
						<div title="修改记录" style="padding:10px">
							<table id="logTable" class="easyui-datagrid" style="width:auto;height:270px;"
								singleSelect="true"
								pagination="true"
								pagePosition="both"
								fitColumns="true"
								rownumbers="true"
								>
						    <thead>
							    <tr>
								    <th data-options="field:'employeeName',width:20">操作人员</th>
								   	<th data-options="field:'logDate',width:20">修改日期</th>
								   	<th data-options="field:'logContent',width:100">修改内容</th>			    
							    </tr>
						    </thead>	
						   </table>
						</div>
					</div>
				</div>
			</div>
</div>
 <div id="dlg" class="easyui-dialog" style="width:1200px;height:500px;padding:10px 20px"
		closed="true">

		<div class="easyui-tabs" id="houseTableTab" style="width:auto;height:auto">
			<div title="房屋信息">
				<form id="fm" method="post" ENCTYPE="multipart/form-data">
				<input type="hidden" name="id2" id="id"/>
				<input type="hidden" name="clazz" id="clazz"/>
					 <div class="ftitle">房屋基本信息</div>		
					<div class="fitem">
						<label>区县</label>
						<select name="districtId" id="bhaId2"   data-options="editable:false" >
						</select>			
						<label>小区</label>
						<select name="unitId" id="unitId"   data-options="editable:false">
							<option value="-1">未知</option>
						</select>	
						<label>门牌号码</label>
						<input type="text"	name="address" id="address"/> 
						<label>楼层</label>
						<input type="text"	name="floor" id="floor" title="整数 如 1 2 3" class="easyui-tooltip"/> 
						<label>总层</label>
						<input type="text"	name="allfloor" id="allfloor" title="整数 如 1 2 3" class="easyui-tooltip"/> 
						<label>朝向</label>
						<select name="face" id="face" data-options="editable:false">
							<option value="其他">其他</option>
							<option value="东">东</option>
							<option value="南">南</option>
							<option value="西">西</option>
							<option value="北">北</option>
							<option value="东南">东南</option>
							<option value="东西">东西</option>
							<option value="南北">南北</option>
							<option value="南南">南南</option>
							<option value="东北">东北</option>
							<option value="西南">西南</option>
							<option value="西北">西北</option>
						</select>
						<label>年代</label>
						<select name="age" id="age"   data-options="editable:false">
							<option value="未知 ">未知</option>
							<option value="2019 ">2019</option>
							<option value="2018">2018</option>
							<option value="2017 ">2017</option>
							<option value="2016">2016</option>
							<option value="2015">2015</option>
							<option value="2014">2014</option>
							<option value="2013">2013</option>
							<option value="2012">2012</option>
							<option value="2011">2011</option>
							<option value="2010">2010</option>
							<option value="2009 ">2009</option>
							<option value="2008">2008</option>
							<option value="2007">2007</option>
							<option value="2006">2006</option>
							<option value="2005">2005</option>
							<option value="2004">2004</option>
							<option value="2003">2003</option>
							<option value="2002">2002</option>
							<option value="2001">2001</option>
							<option value="2000">2000</option>
							<option value="1999">1999</option>
							<option value="1998">1998</option>
							<option value="1997">1997</option>
							<option value="1996">1996</option>
							<option value="1995">1995</option>
							<option value="1994">1994</option>
							<option value="1993">1993</option>
							<option value="1992">1992</option>
							<option value="1991">1991</option>
							<option value="1990">1990</option>
							<option value="1989">1989</option>
							<option value="1988 ">1988</option>
							<option value="1987">1987</option>
							<option value="1986">1986</option>
							<option value="1985">1985</option>
							<option value="1984">1984</option>
							<option value="1983">1983</option>
							<option value="1982">1982</option>
							<option value="1981">1981</option>
						</select>
				      </div>
				      <div class="fitem">
				       <label>户型</label>
				        <select name="room" id="room"   data-options="editable:false">
				        	<option value="0">0</option>
				        	<option value="1">1</option>
				        	<option value="2">2</option>
				        	<option value="3">3</option>
				        	<option value="4">4</option>
				        	<option value="5">5</option>
				        	<option value="6">6</option>
				        	<option value="7">7</option>
				        	<option value="8">8</option>
				        </select>室
				       	<select name="ting" id="ting"   data-options="editable:false">
				      		<option value="0">0</option>
				        	<option value="1">1</option>
				        	<option value="2">2</option>
				        	<option value="3">3</option>
				        	<option value="4">4</option>
				        </select>厅
				        <select name="kitchen" id="kitchen"   data-options="editable:false">
				        	<option value="0">0</option>
				        	<option value="1">1</option>
				        	<option value="2">2</option>
				        	<option value="3">3</option>
				        </select>厨
				        <select name="wei" id="wei"   data-options="editable:false">
				        	<option value="0">0</option>
				        	<option value="1">1</option>
				        	<option value="2">2</option>
				        	<option value="3">3</option>
				        	<option value="4">4</option>
				        </select>卫
				        <select name="balcony" id="balcony"   data-options="editable:false">
				        	<option value="0">0</option>
				        	<option value="1">1</option>
				        	<option value="2">2</option>
				        	<option value="3">3</option>
				        </select>阳台
				        <label>装修</label>
				        <select name="decoration"  id="decoration2" data-options="editable:false">
							<option value="-1">未知</option>
							<option value="1">毛坯</option>
							<option value="2">简单装修</option>
							<option value="3">中等装修</option>
							<option value="4">精装修</option>
							<option value="5">豪华装修</option>
						</select>	
						<label>性质</label>		
						<select name="property"  id="property" data-options="editable:false">
							<option value="公盘">公盘</option>
							<option value="私盘">私盘</option>
							<option value="锁盘">锁盘</option>
							<option value="特盘">特盘</option>
						</select>	
					  </div>
				   <div class="fitem">
				   	<label>类型</label>
				   	<select name="type"  id="type" data-options="editable:false">
							<option value="多层住宅">多层住宅</option>
							<option value="小高层">小高层</option>
							<option value="高层住宅">高层住宅</option>
							<option value="公寓">公寓</option>
							<option value="商铺">商铺</option>
							<option value="写字楼">写字楼</option>
							<option value="商住楼">商住楼</option>
							<option value="独栋别墅">独栋别墅</option>
							<option value="联排别墅">联排别墅</option>
							<option value="叠加别墅">叠加别墅</option>
							<option value="双拼别墅">双拼别墅</option>
							<option value="多层复式">多层复式</option>
							<option value="民房">民房</option>
							<option value="洋房">洋房</option>
							<option value="四合院">四合院</option>
							<option value="厂房">厂房</option>
							<option value="车库">车库</option>
							<option value="地皮">地皮</option>
							<option value="其他">其他</option>
						</select>	
						<label>产权</label>
						<select name="owner"  id="owner" data-options="editable:false">
							<option value="个人">个人</option>
							<option value="单位">单位</option>
							<option value="售后">售后</option>
							<option value="家庭成员共有">家庭成员共有</option>
							<option value="使用权">使用权</option>
							<option value="小产权">小产权</option>
							<option value="协议房">协议房</option>
							<option value="私产">私产</option>
							<option value="公产">公产</option>
							<option value="合同发票">合同发票</option>
							<option value="三联单">三联单</option>
							<option value="其他">其他</option>
						</select>
						<label>钥匙编号</label>
						<input type="text" name="keynumber" id="keynumber"/>
						<label>建筑面积</label>
						<input type="text" name="saleArea" id="saleArea"/>
						<label>来源</label>
						<select name="source"  id="source" data-options="editable:false">
							<option value="来访">来访</option>
							<option value="来电">来电</option>
							<option value="来访">来访</option>
							<option value="中介">中介</option>
							<option value="朋友">朋友</option>
							<option value="扫街">扫街</option>
							<option value="网络">网络</option>
							<option value="独家">独家</option>
							<option value="传单">传单</option>
							<option value="导入">导入</option>
							<option value="其他">其他</option>
						</select>
				   </div>
				   <div class="fitem">
				   	<label>结构</label>
				     <select name="struct"  id="struct" data-options="editable:false">
							<option value="框架">框架</option>
							<option value="砖混">砖混</option>
							<option value="剪力">剪力</option>
							<option value="钢混">钢混</option>
							<option value="木混">木混</option>
							<option value="砖木">砖木</option>
							<option value="其他">其他</option>
						</select>
						<label>产证</label>
						<input type="text" name="premises" id="premises"/>
						<label>车库</label>
						<input type="text" name="garage" id="garage"/>		
						<label>使用面积</label>
						<input type="text" name="actualArea" id="actualArea"/>
						<label>板块</label>
						<select  name="blockId2" id="blockId" data-options="editable:false">
						</select>
				   </div>
				   <div class="fitem">
				   		<label>设施</label>
				   		<select name="establishment" id="establishment" style="width:500px;"></select>
				   </div>
					<div class="fitem" style="width:auto;">
						<label style="vertical-align: top; width: 30px;">房源备注</label>
						<textarea name="houseMark" id="houseMark"></textarea>
					</div>
					<div class="fitem" style="width:auto;">
						<label>图片</label>
						<input type="file" name="file"/>
					</div>
					<div class="ftitle">业务信息</div>		
					<div class="fitem">
				   		<label>总价</label>
				   		<input  type="text" name="allprice" id="allprice"/>万
				   		<label>单价</label>
				   		<input  type="text" name="unitprice" id="unitprice"/>元/M<sup>2</sup>
				   		<label>付款方式</label>
						<select name="way"  id="way" data-options="editable:false">
							<option value="可按揭">可按揭</option>
							<option value="全款">全款</option>
						</select>
						<label>交付时间</label>
						<input name="deliveryData" id="deliveryData"></input>
				   </div>
				   <div class="fitem">
				  		 <label>编号</label>
				   		<input  type="text" id="houseNumber" value="系统自动生成" disabled="disabled"/>
				   		<label>状态</label>
						<select name="status"  id="status" data-options="editable:false">
							<option value="正常">正常</option>
							<option value="推荐">推荐</option>
							<option value="急售">急售</option>
							<option value="待审">待审</option>
							<option value="暂不售">暂不售</option>
							<option value="电话无效">电话无效</option>
							<option value="成交">成交</option>
							<option value="已卖">已卖</option>
							<option value="无效">无效</option>
						</select>
						<label>价格条件</label>
						<select name="pricecondition"  id="pricecondition" data-options="editable:false">
							<option value="一口价">一口价</option>
							<option value="大概价">大概价</option>
							<option value="有双税">有双税</option>
							<option value="无双税">无双税</option>
							<option value="有营业税">有营业税</option>
							<option value="无营业税">无营业税</option>
						</select>
						<label>看房方式</label>
						<select name="visit"  id="visit" data-options="editable:false">
							<option value="随时">随时</option>
							<option value="预约">预约</option>
							<option value="钥匙">钥匙</option>
						</select>
				   </div>	
					<div class="ftitle">业主信息</div>		
					<div class="fitem">
						<label>姓名</label>
						<input type="text" name="ownerName" id="ownerName" >
						<select name="ownerType"  id="cusType" data-options="editable:false">
							<option value="普通客户">普通客户</option>
							<option value="VIP">VIP</option>
							<option value="潜在客户">潜在客户</option>
						</select>
					</div>
					<div class="fitem" style="width:auto;">
						<label>电话</label>
						<input type="text"  name="ownerPhone"  id="ownerPhone" style="width:500px;">
					</div>
					<div class="fitem" style="width:auto;">
						<label style="vertical-align: top;" >备注:</label>
						<textarea name="ownerMark" id="ownerMark"></textarea>
					</div>
					<div class="ftitle"></div>	
					<div id="dlg-buttons" style="text-align: right;">
						<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-ok" onclick="saveHouse()">保存</a>
						<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')">取消</a>
					</div>	
				</form>
			</div>
			<div title="图片浏览">
				<div id="showPhoto" style="margin: 2px;">
					 
				</div>
			</div>
		</div>

	
		
	</div>	
	 <div id="dlgprocess" class="easyui-dialog" style="width:600px;height:auto;padding:10px 20px"
		closed="true">
		<form id="fmp" method="post" action="${pageContext.request.contextPath}/cusProgress/addCusProgress.html">
		<input type="hidden" name="cus_id" id="cus_id"/>
			<div class="ftitle">房屋跟进</div>		
			<div class="fitem">
				<label style="width: 30px;">类型</label>
				<select name="progressType" id="progressType" data-options="editable:false">
					<option value="电话">电话</option>
					<option value="拜访">拜访</option>
					<option value="预约">预约</option>
				</select>
			</div>
			<div class="fitem" style="width:auto;">
				<label style="vertical-align: top; width: 30px;">跟进内容</label>
				<textarea name="content" id="content"></textarea>
			</div>
 		<div class="ftitle"></div>	
			<div id="dlg-buttons" style="text-align: right;">
				<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-ok" onclick="saveProgress()">保存</a>
				<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlgprocess').dialog('close')">取消</a>
			</div>	
 	</div>
<div id="sp">
</div>	 
 <div id="addHouse">
	<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="newHouse('all')">添加</a>		
	<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="editHouse('all');">修改</a>	
	<select name="selshopId" id="selshopId" class="easyui-combobox"  data-options="editable:false">
	</select>	
	<select name="employeeId" id="employeeId" class="easyui-combobox"  data-options="editable:false">
	</select>	
</div>    

<div id="addProgress">
	<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="newProgress()">添加跟进</a>		
</div>
<script type="text/javascript">
	var url = "";
	//打开新建房屋对话框
	function newHouse(arg) {
		 $("#fm file").val('');
		 $("textarea").val('');
		 $("#fm input").val('');
		   $("#unitId").combobox();	
			$("#face").combobox();
			$("#age").combobox();
			$("#room").combobox();
			$("#ting").combobox();
			$("#kitchen").combobox();
			$("#balcony").combobox();
			$("#wei").combobox();
			$("#decoration2").combobox();
			$("#property").combobox();
			$("#type").combobox();
			$("#owner").combobox();
			$("#source").combobox();
			$("#struct").combobox();
			$("#establishment").combobox();
			$("#way").combobox();
			$("#pricecondition").combobox();
			$("#status").combobox();
		    $('#deliveryData').datebox();
		    $("#pricecondition").combobox();
		    $("#visit").combobox();
		    $("#cusType").combobox();
		    $("#blockId").combobox();

		    packageEstablishment();
		    $('#dlg').dialog('open').dialog('setTitle','新建房屋');
		url = "${pageContext.request.contextPath}/house/addNewHouse/"+((gclazz == '新房')?'new':(gclazz == '二手')?'old':'rent')+".html";
		$.ajax({  
			   type: "POST",  
			   url: "district/viewAllDistrictsJson.html",  
			   dataType:"json",  
			   success: function(json){
			     $("#bhaId2").combobox({  
			        data:json.rows,  
			        valueField:'bha_id',  
			        textField:'bhaName',
			        onSelect:function(rec) {
				        	$.ajax({  
				 			   type: "POST",  
				 			   url: "unit/getAllUnitJson/"+rec.bha_id+".html",  
				 			   dataType:"Json",  
				 			   success:function(json){
				 				  $("#unitId").combobox({  
				 				        data:json.rows,  
				 				        valueField:'unitId',  
				 				        textField:'unitName',
				 				        onSelect:function(rec2) {
				 				        	selectBlock(rec2.blockId,rec2.blockName);
				 				        }
				 				  });
				 			   }
				        	});
			        }
			     });
			   }
		});
		
	
	}
	//设置板块
	function selectBlock(id,name) {
		$("#blockId").combobox('clear');	
	     $("#blockId").combobox('setValue',id);
		 $("#blockId").combobox('setText',name);
	}
	
	//组装设备PANEL
	function packageEstablishment() {
			$('#sp').html("");
			$('#sp').append("<div style='color:#99BBE8;background:#fafafa;padding:5px;'>设施设备</div>");
			$('#sp').append("<input type='checkbox' name='lang' value='01'><span>水</span>");
			$('#sp').append("<input type='checkbox' name='lang' value='02'><span>电</span>");
			$('#sp').append("<input type='checkbox' name='lang' value='03'><span>煤气/天然气</span>");
			$('#sp').append("<input type='checkbox' name='lang' value='04'><span>有线电视</span>");
			$('#sp').append("<input type='checkbox' name='lang' value='05'><span>冰箱</span>");
			$('#sp').append("<input type='checkbox' name='lang' value='06'><span>洗衣机</span>");
			$('#sp').append("<input type='checkbox' name='lang' value='07'><span>空调</span><br/>");
			$('#sp').append("<input type='checkbox' name='lang' value='08'><span>微波炉</span>");
			$('#sp').append("<input type='checkbox' name='lang' value='09'><span>热水器</span>");
			$('#sp').append("<input type='checkbox' name='lang' value='10'><span>暖气</span>");
			$('#sp').append("<input type='checkbox' name='lang' value='11'><span>宽带</span>");
			$('#sp').append("<input type='checkbox' name='lang' value='12'><span>电话</span>");
			$('#sp').append("<input type='checkbox' name='lang' value='13'><span>电梯</span>");
			$('#sp').append("<input type='checkbox' name='lang' value='14'><span>储藏室/地下室</span><br/>");
			$('#sp').append("<input type='checkbox' name='lang' value='15'><span>灶具</span>");
			$('#sp').append("<input type='checkbox' name='lang' value='16'><span>家具</span>");
			$('#sp').append("<input type='checkbox' name='lang' value='17'><span>露台/花园</span>");
			$('#sp').append("<input type='checkbox' name='lang' value='18'><span>停车位</span>");	
			$('#sp').append("<input type='checkbox' name='lang' value='19'><span>物业服务</span>");
			$('#sp').append("<input type='checkbox' name='lang' value='20'><span>商务中心</span>");;
			$('#sp').append("<input type='checkbox' name='lang' value='21'><span>健身设备</span>");
			
			$('#sp').appendTo($('#establishment').combo('panel'));
			 var s = '';
			 var v = '';
			 $('#sp input').click(function(){
				 s = '';
				 v = '';
				 $('#establishment').combo('setValue', '').combo('setText','');	
				$("input:checked").each(function(){
					 v += $(this).val() + ",";
					 s += $(this).next('span').text() + " ";

				});
				alert(v);
				  $('#establishment').combo('setValue', v);	
				 $('#establishment').combo('setText', s);
			});
			
	}
	
	//打开编辑房屋对话框
	function editHouse() {
		 var row = $('#houseAll').datagrid('getSelected');
		 if (row){
			 $(":file").val('');
			 $("textarea").val('');
			 $("#unitId").combobox();	
			 $("#face").combobox();
			 $("#age").combobox();
			 $("#room").combobox();
			 $("#ting").combobox();
			 $("#kitchen").combobox();
			 $("#balcony").combobox();
			 $("#wei").combobox();
			 $("#decoration2").combobox();
			 $("#property").combobox();
			 $("#type").combobox();
			 $("#owner").combobox();
			 $("#source").combobox();
			 $("#struct").combobox();
			 $("#establishment").combobox();
			 $("#way").combobox();
			 $("#pricecondition").combobox();
			 $("#status").combobox();
			 $('#deliveryData').datebox();
			 $("#pricecondition").combobox();
			 $("#visit").combobox();
			 $("#cusType").combobox();
			 $("#blockId").combobox();
			 packageEstablishment();
			 fillData(row);
			 
		 $('#dlg').dialog('open').dialog('setTitle','编辑房屋');	 
			 //获取图片
			 $.ajax({  
				   type: "GET",  
				   url: "photo/getPhotoJson.html?houseId="+row.id,  
				   success: function(json){  
						 $("#showPhoto").html("");
					    var data = json.rows;
						$.each(data,function(index,name){
							$("#showPhoto").append("<div style='margin: 2px;'><img src=${pageContext.request.contextPath}/fileupload/"+data[index].url+" width='600px;'></div>");
						});
				   }
				}); 			
		//区域
		 $.ajax({  
			   type: "POST",  
			   url: "district/viewAllDistrictsJson.html",  
			   dataType:"json",  
			   success: function(json){
			     $("#bhaId2").combobox({  
			        data:json.rows,  
			        valueField:'bha_id',  
			        textField:'bhaName',
			        onSelect:function(rec) {
			        	$.ajax({  
			 			   type: "POST",  
			 			   url: "unit/getAllUnitJson/"+rec.bha_id+".html",  
			 			   dataType:"Json",  
			 			   success:function(json){
			 				  $("#unitId").combobox({  
			 				        data:json.rows,  
			 				        valueField:'unitId',  
			 				        textField:'unitName',
			 				        onSelect:function(rec2) {
			 				        	selectBlock(rec2.blockId,rec2.blockName);
			 				        }
			 				  });
			 			   }
			        	});
			        }});
			     $("#bhaId2").combobox('setValue',row.districtId);
				 $("#bhaId2").combobox('setText',row.districtName);
				 $("#bhaId2").combobox('select',row.districtId);
				 //小区
		        	$.ajax({  
			 			   type: "POST",  
			 			   url: "unit/getAllUnitJson/"+row.districtId+".html",  
			 			   dataType:"Json",  
			 			   success:function(json){
			 				  $("#unitId").combobox({  
			 				        data:json.rows,  
			 				        valueField:'unitId',  
			 				        textField:'unitName',
			 				        onSelect:function(rec2) {
			 				        	selectBlock(rec2.blockId,rec2.blockName);
			 				        }
			 				  });
			 			     $("#unitId").combobox('setValue',row.unitId);
							 $("#unitId").combobox('setText',row.unitName);
							 $("#unitId").combobox('select',row.unitId);
							
			 			   }
			        	});
			   }});


		 }else {
			 $.messager.show({
				 title: '提示',
				 msg: "请选择一条数据"
				 });
		 }
	}
	
	/**
	*
	* 填充数据
	**/
	function fillData(row) {
		//id
		$("#id").val(row.id);
		//clazz
		$("clazz").val(row.clazz);
		//address
		$("#address").val(row.address);
		$("#address").text(row.address);
		//floor
		$("#floor").val(row.floor);
		$("#floor").text(row.floor);
		//allfloor
		$("#allfloor").val(row.allfloor);
		$("#allfloor").text(row.allfloor);
		//room
		$("#room").combobox('setValue', row.room);
		$("#room").combobox('setText', row.room);
		$("#room").combobox('select', row.room);
		//living room
		$("#ting").combobox('setValue', row.ting);
		$("#ting").combobox('setText', row.ting);
		$("#ting").combobox('select', row.ting);
		//kitchen
		$("#kitchen").combobox('setValue', row.kitchen);
		$("#kitchen").combobox('setText', row.kitchen);
		$("#kitchen").combobox('select', row.kitchen);
		//toitle
		$("#wei").combobox('setValue', row.wei);
		$("#wei").combobox('setText', row.wei);
		$("#wei").combobox('select', row.wei);
		//balcony
		$("#balcony").combobox('setValue', row.balcony);
		$("#balcony").combobox('setText', row.balcony);
		$("#balcony").combobox('select', row.balcony);
		//朝向
		$("#face").combobox('setValue', row.face);
		$("#face").combobox('setText', row.face);
		$("#face").combobox('select', row.face);
		//age
		$("#age").combobox('setValue', row.age);
		$("#age").combobox('setText', row.age);
		$("#age").combobox('select', row.age);
		//decoration
		$("#decoration2").combobox('setValue', row.decorationId);
		$("#decoration2").combobox('setText', row.decoration);
		$("#decoration2").combobox('select', row.decorationId);
		//property
		$("#property").combobox('setValue', row.property);
		$("#property").combobox('setText', row.property);
		$("#property").combobox('select', row.property);
		//type
		$("#type").combobox('setValue', row.type);
		$("#type").combobox('setText', row.type);
		$("#type").combobox('select', row.type);
		//owner
		$("#owner").combobox('setValue', row.owner);
		$("#owner").combobox('setText', row.owner);
		$("#owner").combobox('select', row.owner);
		//key
		$("#keynumber").val(row.keynumber);
		$("#keynumber").text(row.keynumber);
		//saleArea
		$("#saleArea").val(row.saleArea);
		$("#saleArea").text(row.saleArea);
		//source
		$("#source").combobox('setValue', row.source);
		$("#source").combobox('setText', row.source);
		$("#source").combobox('select', row.source);
		//struct
		$("#struct").combobox('setValue', row.struct);
		$("#struct").combobox('setText', row.struct);
		$("#struct").combobox('select', row.struct);
		//premises
		$("#premises").val(row.premises);
		$("#premises").text(row.premises);
		//garage
		$("#garage").val(row.garage);
		$("#garage").text(row.garage);
		//actualArea
		$("#actualArea").val(row.actualArea);
		$("#actualArea").text(row.actualArea);
		//establishment
		var array = row.establishment.split(",");
		var len = array.length-1;
		var s = "";
		for(var i = 0 ; i < len; i++ ) {
			var value = array[i];
			var checkbox = $("#sp input[value="+value+"]");
			checkbox.attr("checked",true);
			s += $(checkbox).next("span").text() + " ";
		}
		$('#establishment').combo('setValue', row.establishment);	
	    $('#establishment').combo('setText', s);
		//houseMark
		$("#houseMark").val(row.houseMark);
		$("#houseMark").text(row.houseMark);
		//allprice
		$("#allprice").val(row.allprice);
		$("#allprice").text(actualArea.allprice);
		//allprice
		$("#unitprice").val(row.unitprice);
		$("#unitprice").text(row.unitprice);
		//way
		$("#way").combobox('setValue', row.way);
		$("#way").combobox('setText', row.way);
		$("#way").combobox('select', row.way);
		//deliveryData
		$('#deliveryData').datebox('setValue', row.deliveryData);
		//houseNumber
		$("#houseNumber").val(row.houseNumber);
		//status
		$("#status").combobox('setValue', row.status);
		$("#status").combobox('setText', row.status);
		$("#status").combobox('select', row.status);
		//pricecondition
		$("#pricecondition").combobox('setValue', row.pricecondition);
		$("#pricecondition").combobox('setText', row.pricecondition);
		$("#pricecondition").combobox('select', row.pricecondition);
		//visit
		$("#visit").combobox('setValue', row.visit);
		$("#visit").combobox('setText', row.visit);
		$("#visit").combobox('select', row.visit);
		//ownerName
		$("#ownerName").val(row.ownerName);
		$("#ownerName").text(row.ownerName);
		//ownerType
		$("#ownerType").combobox('setValue', row.ownerType);
		$("#ownerType").combobox('setText', row.ownerType);
		$("#ownerType").combobox('select', row.ownerType);
		//ownerPhone
		$("#ownerPhone").val(row.ownerPhone);
		$("#ownerPhone").text(row.ownerPhone);
		//ownerMark
		$("#ownerMark").val(row.ownerMark);
		$("#ownerMark").text(row.ownerMark);
		//deliveryData
		 url = "${pageContext.request.contextPath}/house/modifyNewHouse.html";
		 
		 
	}
	
	 function saveHouse(){
		 $('#fm').form('submit',{
		 url:url,
		 onSubmit: function(){
			 return $(this).form('validate');
		 },
		 success: function(result){
			 var result = eval('('+result+')');
			 if (result.errorMsg){
				 $.messager.show({
				 title: 'Error',
				 msg: result.errorMsg
				 });
			 } else {
				 
				 $('#dlg').dialog('close'); // close the dialog
				 $('#searhfm').form('submit',{
					 success: function(result){
						 var result = eval('('+result+')');
						 if (result.errorMsg){
							 $.messager.show({
							 title: 'Error',
							 msg: result.errorMsg
							 });
						 } else {
							 $('#houseAll').datagrid({
									data: result
								});
							 $.messager.show({
								 title: '成功',
								 msg: "数据添加成功"
								 });
							 $('#logTable').datagrid('reload');
						 }
					 	}
					 });

			 }
		 	}
		 });
		}
	
	 
	
	
	function favorite(arg) {
		 var row = $("#"+arg+"").datagrid('getSelected');
		 if (row){
				$.getJSON("house/addFavorite.html?houseId=" + row.houseId,
						function(result) {
						if (result["errorMsg"]){
							 $.messager.show({
							 title: 'Error',
							 msg: result.errorMsg
							 });
						 } else {
							 $.messager.show({
								 title: '成功',
								 msg: "数据添加成功"
								 });
						 }
						});
		 }else {
			 $.messager.show({
				 title: '提示',
				 msg: "请选择一条数据"
				 });
		 }
	}
	
	//打开新建跟进对话框
	function newProgress() {
		$("textarea").val("");
		$("#progressType").combobox();
		 var row = $('#houseAll').datagrid('getSelected');
		 if (row){
			$('#dlgprocess').dialog('open').dialog('setTitle','新建跟进');	 
		 }else {
			 $.messager.show({
				 title: '提示',
				 msg: "请选择一条数据"
				 });
		 }
	}
	
	 function saveProgress(){
		 var row = $('#houseAll').datagrid('getSelected');
		 $("#cus_id").val('h'+row.id);
		 $('#fmp').form('submit',{
		 success: function(result){
			 var result = eval('('+result+')');
			 if (result.errorMsg){
				 $.messager.show({
				 title: 'Error',
				 msg: result.errorMsg
				 });
			 } else {
				 
				 $('#dlgprocess').dialog('close'); // close the dialog
				 $.messager.show({
					 title: '成功',
					 msg: "数据添加成功"
					 });
				 $('#ProgressTable').datagrid('reload');

			 }
		 	}
		 });
		}
	
	function setBlockName() {
		$('#blockName').val($("#bankuaiId").find("option:selected").text());
	}
</script>
